class IndexController < ApplicationController
  
  def index
    subdomain = request.subdomains[0]
    if subdomain && subdomain != "www"
      @user = User.find_by_login(subdomain)
      if @user
        @blogs = Blog.find(:all, :limit => 10, :conditions => ['user_id = ?', @user.id], :order => 'created_at desc')
        @tutorials = Tutorial.find(:all, :limit => 10, :conditions => ['user_id = ?', @user.id], :order => 'created_at desc')
        @resources = Resource.find(:all, :limit => 10, :conditions => ['user_id = ?', @user.id], :order => 'created_at desc')
        @forums = Post.find(:all, :limit => 10, :conditions => ['user_id = ?', @user.id], :order => 'created_at desc')
      else
        redirect_to "/not_found"
      end
    else
      @blogs = Blog.find(:all, :limit => 10, :order => 'created_at desc')
      @tutorials = Tutorial.find(:all, :limit => 10, :order => 'created_at desc')
      @resources = Resource.find(:all, :limit => 10, :order => 'created_at desc')
      @forums = Post.find(:all, :limit => 10, :order => 'created_at desc')
    end
  end

end